package com.hsd.whb.pojo.input;

import com.hsd.whb.enums.ResultEnum;
import com.hsd.whb.exception.HwbException;
import com.hsd.whb.utils.ResultVOUtil;
import lombok.Data;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.security.crypto.password.PasswordEncoder;

@Data
public class ModifyPassword {

    private String prePassword;

    private String password;

    @NotBlank(message = "新密码不能为空")
    private String newPassword;

    private String confirmPassword;

    public void valid(PasswordEncoder passwordEncoder) {
        if (!newPassword.equals(confirmPassword)) {
            throw new HwbException(ResultEnum.NOT_SAME_PASSWORD);
        }
        if (!passwordEncoder.matches(password, prePassword)) {
            throw new HwbException(ResultEnum.PASSWORD_ERROR);
        }
        if (newPassword.equals(password)) {
            throw new HwbException(ResultEnum.PASSWORD_PREPASSWORD_SAME_ERROR);
        }
    }

}
